import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class PlanReader {
    public void read_plan(){
        String file = "d:/java/xml/src/plan.xml";
        SAXReader reader = new SAXReader();
        try{
            Document document = reader.read(file);
            Element root = document.getRootElement();
            List<Element> courses = root.elements("course");
            for (Element course:courses){
                String course_name = course.elementText("course_name");
                String class_hour = course.elementText("class_hour");
                String exam_form = course.elementText("exam_form");
                String attribute = course.attribute("no").getText();
                System.out.println("课程编号："+attribute);
                System.out.println("课程名称："+course_name);
                System.out.println("课时："+class_hour);
                System.out.println("考试方式："+exam_form);
                System.out.println("==================================");
            }

        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        PlanReader planReader = new PlanReader();
        planReader.read_plan();
    }
}
